//
//  Select.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/17.
//

#import "Select.h"
@interface Select()<UITextFieldDelegate>
@end

@implementation Select

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(12);
    }];
    UIView *view = [UIView new];
    view.backgroundColor  = UIColor.clearColor;
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.left.mas_offset(KWidth(12));
        make.right.mas_offset(KWidth(-12));
        make.height.mas_equalTo(52);
        make.bottom.mas_offset(-10);
    }];
    
    UIImageView *bg= [UIImageView new];
    bg.contentMode = UIViewContentModeScaleAspectFill;
    bg.image = [UIImage imageNamed:@"textBG"];
    
    [view addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    
    [view addSubview:self.name];
    [_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.right.mas_offset(-10);
        make.top.bottom.mas_equalTo(view);
    }];
    
    [view addSubview:self.detailImg];
    [_detailImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-10);
        make.centerY.mas_equalTo(view);
    }];
}

-(UITextField *)name
{
    if (!_name) {
        _name = [UITextField new];
        _name.font = [UIFont systemFontOfSize:16];
        _name.textColor = UIColor.blackColor;
        _name.delegate = self;
    }
    return _name;
}

-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font  = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        _titleLabel.textColor = HexColor(@"#000000");
    }
    return _titleLabel;
}

-(UIImageView *)detailImg
{
    if (!_detailImg) {
        _detailImg = [UIImageView new];
    }
    return _detailImg;
}

-(void)setPlaceHolder:(NSString *)placeHolder
{
    NSDictionary *attributes = @{
        NSForegroundColorAttributeName: [UIColor lightGrayColor],
        NSFontAttributeName: [UIFont systemFontOfSize:14]
    };
    self.name.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeHolder attributes:attributes];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
